using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Mocks;
using NUnit.Framework;

namespace Hawkeye.Specs
{
  [TestFixture]
  public class Story_HawkService
  {
    [Test]
    public void Example1()
    {
      Given_input("class T {}");
      Should_find_classes("T");
      Should_compute_frequency("T", 1);
    }

    [Test]
    public void Example2()
    {
      Given_input("class T {} public class S { .. }");
      Should_find_classes("T", "S");
      Should_compute_frequency("T", 1);
      Should_compute_frequency("S", 1);
    }

    [Test]
    public void Example3()
    {
      Given_input("class T {} class T {} class test ");
      Should_find_classes("T");
      Should_compute_frequency("T", 2);
    }

    [Test]
    public void Example4()
    {
      Given_input("class Test {} Test() Testar Test ");
      Should_compute_frequency("Test", 3);
    }

    [TearDown]
    public void After_each()
    {
      mock.Expect("ProduceFrequenceReport");
      hawkservice.ProduceFrequencyTable(new Dictionary<string, int>());
      mock.Verify();
    }

    private void Given_input(string text)
    {
      mock = new DynamicMock(typeof(HawkService.IService));
      hawkservice = new HawkService((HawkService.IService)mock.MockInstance);
      input = text;
    }

    private void Should_find_classes(params string[] expected)
    {
      List<string> got = hawkservice.FindClassNames(input);
      CollectionAssert.AreEqual(expected, got);
    }

    private void Should_compute_frequency(string classname, int expected)
    {
      int got = hawkservice.CountFrequency(input, classname);
      Assert.AreEqual(expected, got);
    }

    HawkService hawkservice;
    string input;
    DynamicMock mock;
  }

}
